package com.example.http.demo.service.impl;

import com.example.http.demo.config.HttpDemoProperties;
import com.example.http.demo.dto.LoginDeveloperDTO;
import com.example.http.demo.dto.RegisterDeveloperDTO;
import com.example.http.demo.dto.UpdateDeveloperKeyDTO;
import com.example.http.demo.reponse.HttpBaseResponse;
import com.example.http.demo.service.DeveloperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class DeveloperServiceImpl implements DeveloperService {


    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private HttpDemoProperties httpDemoProperties;


    @Override
    public void registerDeveloper(RegisterDeveloperDTO developerDTO) {
        //1.请求三方注册的接口
        String requestUrl = httpDemoProperties.getRequestBaseUrl() + httpDemoProperties.getDeveloperRegisterUrl();
        ResponseEntity<HttpBaseResponse> baseResponseResponseEntity = this.restTemplate.postForEntity(requestUrl, null, HttpBaseResponse.class,
                developerDTO.getName(), developerDTO.getPassword(), developerDTO.getEmail());
        //2.保存请求
        //3.保存响应
        System.out.println("响应：" + baseResponseResponseEntity.getBody());
    }

    @Override
    public void loginDeveloper(LoginDeveloperDTO loginDeveloperDTO) {
//1.请求三方注册的接口
        String requestUrl = httpDemoProperties.getRequestBaseUrl() + httpDemoProperties.getDeveloperLoginUrl();
        ResponseEntity<HttpBaseResponse> baseResponseResponseEntity = this.restTemplate.postForEntity(requestUrl, null, HttpBaseResponse.class,
                loginDeveloperDTO.getName(), loginDeveloperDTO.getPassword());
        //2.保存请求
        //3.保存响应
        System.out.println("响应：" + baseResponseResponseEntity.getBody());
    }

    @Override
    public void updateDeveloperKey(UpdateDeveloperKeyDTO updateDeveloperKeyDTO) {


        //1.请求三方注册的接口
        String requestUrl = httpDemoProperties.getRequestBaseUrl() + httpDemoProperties.getDeveloperUpdateKeyUrl();
        ResponseEntity<HttpBaseResponse> baseResponseResponseEntity = this.restTemplate.postForEntity(requestUrl, null, HttpBaseResponse.class,
                updateDeveloperKeyDTO.getName(), updateDeveloperKeyDTO.getPassword());
        //2.保存请求
        //3.保存响应
        System.out.println("响应：" + baseResponseResponseEntity.getBody());
    }
}
